//https://leetcode.cn/problems/multiply-strings/
//解法1:1.先转化为整数-数组；2.然后每位进行相乘运算；
#include <vector>
#include <string>
#include <queue>

using namespace std;

class Solution {
public:
    std::vector<int> mul(std::vector<int>& A, std::vector<int>& B) {
        std::vector<int> C(A.size() + B.size(), 0);
        for (int i = 0; i < A.size(); ++i) {
            for (int j = 0; j < B.size(); ++j) {
                C[i + j] += A[i] * B[j];
            }
        }
        int carry = 0;
        for (int i = 0; i < C.size(); i++) {
            carry += C[i];
            C[i] = carry % 10;
            carry /= 10;
        }
        while (C.size() > 1 && C.back() == 0) {
            C.pop_back();
        }
        return C;
    }
    string multiply(string num1, string num2) {
        if (num1.empty() || num2.empty())
            return "";
        std::vector<int> A, B;
        for (int i = num1.size() - 1; i >= 0; --i) {
            A.push_back(num1[i] - '0');
        }
        for (int i = num2.size() - 1; i >= 0; --i) {
            B.push_back(num2[i] - '0');
        }
        std::vector<int> C = mul(A, B);
        std::string res = "";
        for (int k = C.size() - 1; k >= 0; k--) {
            res = res + std::to_string(C[k]);
        }
        return res;
    }
};